package com.taotao.search.server.controller;

import com.taotao.common.core.domain.Result;
import com.taotao.search.request.SearchParam;
import com.taotao.search.response.ProductSkuResponse;
import com.taotao.search.server.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.taotao.search.server.domain.SearchResult;

import java.io.IOException;
import java.util.List;

/**
 * @className: SearchController
 * @author: ZhangYuQi
 * @date: 2024/12/19 下午5:28
 * @Version: 1.0
 * @description:
 */

@RestController
public class SearchController {

    @Autowired
    private ProductService productService;

    /**
    * @Author ZhangYuQi
    * @Description 搜索
    * @Date 下午4:50 2024/12/20
    * @Param [param]
    * @return
    */
    @GetMapping()
    public Result<SearchResult> search(SearchParam param) throws IOException {
        SearchResult result = productService.search(param);
        return Result.success(result);
    }



    /**
    * @Author ZhangYuQi
    * @Description 上传至es中
    * @Date 下午8:10 2024/12/19
    * @Param [products]
    * @return
    */
    @PostMapping("saveProduct")
    public Result saveProduct(@RequestBody List<ProductSkuResponse> products){
        productService.saveProduct(products);
        return Result.success();
    }

}
